#include <gtk/gtk.h>
#include "main_win.h"

#define DIORD_DET "n个元素有n!个不同\n的排序。将这n!个排序\n按字典排序并编号。\n每个排序的编号为其\n字典序值。"
#define SORT_DET "用关系“<”和“=”将数\n进行排序。"
#define GRID_DET "布线区域划分为nXm个\n方格阵列，要求确定的\n两个方格之间的最短\n布线方案。"

static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data){
        return FALSE;
}

static void destroy(GtkWidget *widget, gpointer data){
        gtk_main_quit();
}

static void clicked_sort(GtkWidget *widget, gpointer data){
	gtk_widget_hide (m_window);
	s_win();
}

static void clicked_diord(GtkWidget *widget, gpointer data){
	gtk_widget_hide (m_window);
	diord_win();
}

static void clicked_grid(GtkWidget *widget, gpointer data){
	gtk_widget_hide (m_window);
	grid_win();
}

/*主界面*/
int m_win(void){
	GtkWidget *button1, *button2, *button3, *vbox1, *vbox2, *vbox3, *label1, *label2, *label3;

	m_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_position (GTK_WINDOW(m_window), GTK_WIN_POS_CENTER_ALWAYS);
	gtk_window_set_icon_from_file (GTK_WINDOW(m_window), LOGO, NULL);
	gtk_window_set_default_size (GTK_WINDOW(m_window), 1, 1);
	gtk_window_set_resizable (GTK_WINDOW(m_window), FALSE);

	g_signal_connect (m_window, "delete-event", G_CALLBACK (delete_event), NULL);
	g_signal_connect (m_window, "destroy", G_CALLBACK (destroy), NULL);

	gtk_container_set_border_width (GTK_CONTAINER (m_window), 100);

	button1 = gtk_button_new_with_label (DIORD);
	button2 = gtk_button_new_with_label (SORT);
	button3 = gtk_button_new_with_label (GRID);

	label1 = gtk_label_new (DIORD_DET);
	label2 = gtk_label_new (SORT_DET);
	label3 = gtk_label_new (GRID_DET);

	vbox1 = gtk_vbox_new (FALSE, 0);
	vbox2 = gtk_vbox_new (FALSE, 0);
	vbox3 = gtk_vbox_new (FALSE, 0);

	g_signal_connect (button1, "clicked", G_CALLBACK (clicked_diord), NULL);
	g_signal_connect (button2, "clicked", G_CALLBACK (clicked_sort), NULL);
	g_signal_connect (button3, "clicked", G_CALLBACK (clicked_grid), NULL);

	gtk_box_pack_start (GTK_BOX (vbox1), button1, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox1), label1, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox2), button2, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox2), label2, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox3), button3, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (vbox3), label3, FALSE, FALSE, 0);

	GtkWidget *box;

	box = gtk_hbox_new (FALSE, 0);

	gtk_box_pack_start (GTK_BOX (box), vbox1, FALSE, FALSE, 10);
	gtk_box_pack_start (GTK_BOX (box), vbox2, FALSE, FALSE, 10);
	gtk_box_pack_start (GTK_BOX (box), vbox3, FALSE, FALSE, 10);

	gtk_container_add (GTK_CONTAINER (m_window), box);

	gtk_widget_show (button1);
	gtk_widget_show (button2);
	gtk_widget_show (button3);
	gtk_widget_show (label1);
	gtk_widget_show (label2);
	gtk_widget_show (label3);
	gtk_widget_show (vbox1);
	gtk_widget_show (vbox2);
	gtk_widget_show (vbox3);
	gtk_widget_show (box);
	gtk_widget_show (m_window);

	return 0;
}
